home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / atconv.arc / ATCONV.C next >
C/C++ Source or Header  |  1987-02-08  |  2KB  |  98 lines

  1. /*
  2.     atconv.c
  3.     
  4.     program to translate ATASCII to ASCII or vice-versa.
  5.     call:
  6.         atconv filename
  7.         
  8.     function: program translates all occurrences of 0x9b to
  9.           ox0d,0x0a and all occurrences of 0x0a to 0x9b.
  10.           Occurrences of 0x0d in the input are ignored.
  11.           The result of this translation is that files in
  12.           ATASCII are readable in ASCII and files in ASCII
  13.           are readable in ATASCII.
  14.           
  15.     warnings: This program writes a temporary file "xyzzy.tmp"
  16.           which replaces the original file upon completion.
  17.           If the user wishes to retain the original file, a copy
  18.           should be made beforehand.
  19.           
  20.     author:      Bruce D. Nelson
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <osbind.h>
  25.  
  26. main (argc, argv)
  27. int     argc;
  28. char   *argv[];
  29. {
  30.     int    c1,dtabuff[22],whway;
  31.     long   l,len;
  32.     FILE   *fp1,*fp2;
  33.  
  34.     if (argc < 2) {
  35.         printf("Usage: atconv filename\n");
  36.         exit();
  37.         }
  38.  
  39.     if ((fp1 = fopen (argv[1], "br")) == NULL) {
  40.         printf ("Can't open %s\n",argv[1]);
  41.             exit();
  42.     }
  43.     if ((fp2 = fopen ("xyzzy.tmp", "bw")) == NULL) {
  44.         printf ("Can't open xyzzy.tmp");
  45.             exit();
  46.     }
  47.  
  48.     Fsetdta (dtabuff);
  49.     Fsfirst (argv[1],0);
  50.     len = *(long *)(dtabuff+13);
  51.     whway = 0; /* indicates which way the translation was assumed */
  52.  
  53.     for (l=0;l<len;l++){
  54.         c1 = fgetc(fp1);
  55.         switch (c1){
  56.             case 0x9b:{
  57.                 whway = 1;
  58.                 wputc(0x0d,fp2);
  59.                 wputc(0x0a,fp2);
  60.                 break;
  61.             }
  62.             case 0x0d:{
  63.                 break;
  64.             }
  65.             case 0x0a:{
  66.                 whway = 2;
  67.                 wputc(0x9b,fp2);
  68.                 break;
  69.             }
  70.             default:{
  71.                 wputc(c1,fp2);
  72.                 break;
  73.             }
  74.         } /* end switch */
  75.     }/* end for */
  76.             
  77.     fclose (fp1);
  78.     fclose (fp2);
  79.  
  80.     Fdelete(argv[1]);
  81.     Frename(0,"xyzzy.tmp",argv[1]);
  82.         
  83.     if (whway == 1) printf ("%s converted from ATASCII to ASCII",argv[1]);
  84.     if (whway == 2) printf ("%s converted from ASCII to ATASCII",argv[1]);
  85.     
  86. }
  87.  
  88. wputc (c,f) /* fputc with error handling */
  89. int c;
  90. FILE *f;
  91. {
  92.     if ((fputc(c,f))==EOF){
  93.         printf ("End of file on temp file\n");
  94.         exit();
  95.     }
  96. }
  97.  
  98.